package com.ssm.mall.controller;

import com.ssm.mall.common.Res;
import com.ssm.mall.dao.entity.User;
import com.ssm.mall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "user")
public class UserController {
    @Autowired
    UserService userService;
    //登录
    @RequestMapping(value = "login.do")
    public @ResponseBody Res<User> login(@RequestParam("username")String username,@RequestParam("password") String password){
        return userService.login(username,password);
    }
//     注册
    @RequestMapping(value = "registry.do")
    public @ResponseBody Res registry(@RequestParam("username")String username,@RequestParam("password") String password,
         @RequestParam(value = "email",required = false,defaultValue = "") String email,@RequestParam(value = "phone",required = false,defaultValue = "")String phone,
          @RequestParam(value = "question",required = false,defaultValue = "")String question,@RequestParam(value = "answer",required = false,defaultValue = "")String answer){
        User user = new User(username,password,email,phone,question,answer);
        return userService.registry(user);
    }
    //校验用户名是否存在
    @RequestMapping(value = "check_valid.do")
    public @ResponseBody Res checkValid(String name,String type){
        return userService.checkValid(name,type);
    }
    // 忘记密码
    @RequestMapping(value = "forget_get_question.do")
    public @ResponseBody Res forgetGetQuestion(String username){
        return userService.forgetGetQuestion(username);
    }


}
